package com.motu.vertx.module.utility.webhandler;

import com.motu.vertx.module.utility.webtool.BaseWebHandler;
import com.motu.vertx.module.utility.webtool.SearchCondition;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.WebClient;
import io.vertx.sqlclient.Pool;

import java.util.ArrayList;
import java.util.List;

public class RecordtypeHandler extends BaseWebHandler{
	public static final String tableName = "recordtype";
	private static Pool jdbcClientCommon = null;

	public static void init(Pool jdbcCommon){
		jdbcClientCommon = jdbcCommon;
	}
	public static void list(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		getTableList(routingContext, jdbcClientCommon,tableName);
	}
	public static void add(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		addToTable(routingContext,jdbcClientCommon, tableName,null);
	}

	public static void update(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		
		updateToTable(routingContext,jdbcClientCommon, tableName,null);
	}

	public static void getone(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		getFromTable(routingContext,jdbcClientCommon, tableName);

	}
	public static void delete(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		deleteFromTable(routingContext,jdbcClientCommon, tableName);
	}

	public static void search(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
//		if(!json.containsKey("key")){
//			list(routingContext, json, adminName);
//			return;
//		}
//
//
//		String key = json.getString("key");
//		String sql1 = "select count(1) FROM "+tableName+" where id = ? or info like ?;"; 
//		JsonArray params1 = new JsonArray();
//		params1.add(key);
//		params1.add("%"+key+"%");
//	
//
//
//		String sql = "select * FROM "+tableName+" where id = ? or info like ? order by id desc  limit ?,?; ";
//		JsonArray params = new JsonArray();
//		params.add(key);
//		params.add("%"+key+"%");
//		int pageNo = json.getInteger("pageNo");
//		int pageSize = json.getInteger("pageSize");
//		int start = pageNo*pageSize;
//		params.add(start);
//		params.add(pageSize);
//
//		searchFromTable(routingContext,jdbcClientCommon, tableName, sql1, params1, sql, params);
		List<SearchCondition> scList = new ArrayList<SearchCondition>();
		scList.add(new SearchCondition("key", "like", new String[]{"id","info"}, null));
		
		searchFromTable(routingContext, jdbcClientCommon, json, tableName, scList);
	}

}
